home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PrinterClassDriver.h
-
- Contains: structures for PrinterClass
-
- Version:
-
- Copyright: © 1997-1999 by Apple Computer, Inc., all rights reserved.
-
- */
- #ifndef __PRINTERCLASSDRIVERH__
- #define __PRINTERCLASSDRIVERH__
-
- #include <MacTypes.h>
- #include <Devices.h>
- #include <DriverServices.h>
- #include <Processes.h>
-
- #ifndef __MIXEDMODE__
- #include <mixedmode.h>
- #endif
-
- #include <USB.h>
-
- #if DEBUG
- #define IF_DEBUG(x) x
- #else
- #define IF_DEBUG(x)
- #endif
-
- #define kStrPrinterClass "PrinterClass: "
- void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
- void ExpertNotify(void *exNote);
-
- #define kPrinterRetryCount 5
-
- /* Move to sys files */
- #define kUSBPrintClass 7
- #define kUSBPrintSubClass 1
-
- #define TRANSFER_SIZE 4096 /* ideally this is the same as VM page size */
-
- // section 5.3 USB Device Class Definition for Printing Devices
- enum {
- kUSBPrintClassGetDeviceID = 0,
- kUSBPrintClassGetCentronicsStatus = 1,
- kUSBPrintClassSoftReset = 2,
- kUSBPrintClassProtocolReserved = 0,
- kUSBPrintClassProtocolUnidirectional = 1,
- kUSBPrintClassProtocolBidirectional = 2,
- // 3..0xFE reserved for future use
- kUSBPrintClassProtocolVendor = 0xFF
- };
-
- enum
- {
- kDrvrCentronicsStatus = 3,
- kDrvr1284IdString = 4,
- kDrvrNumDevices = 5,
- kDrvrSoftReset = 6,
- kDrvrPrivateSetStorage = 128
- };
-
- enum driverstages
- {
- kUndefined = 0,
- kNilCompletion,
- kFindInterface_bidirectional,
- kFindInterface_unidirectional,
- kOpenDevice,
- kNewInterfaceRef,
- kSetInterface,
- kConfigureInterface,
- kGetCapabilityString,
- kDelayGetCapability,
- kAllocateCapabilityMem,
- kGetFullCapabilityString,
- kGetInterface,
- kFindBulkOutPipe,
- kFindBulkInPipe,
- kTaskTimeRequired,
-
- kGetCentronicsStatus,
- kDelayGetCentronicsStatus,
-
- kDeallocateCapbilityString,
-
- kReturnFromDriver = 0x1000,
- kRetryTransaction = 0x2000,
- kTransactionPending = 0x8000
- };
-
- enum {
- uppIODoneProcInfo = kRegisterBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
- | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
-
- uppQueueUSBReadProcInfo = kCStackBased
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
-
- uppQueueUSBWriteProcInfo = kCStackBased
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
-
- uppAbortProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
-
- uppControlStatusProcInfo = kCStackBased
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
- };
-
- #if GENERATINGCFM
- typedef UniversalProcPtr QueueUSBReadUPP;
- typedef UniversalProcPtr QueueUSBWriteUPP;
- typedef UniversalProcPtr IODoneUPP;
- typedef UniversalProcPtr AbortUPP;
- typedef UniversalProcPtr ControlStatusUPP;
- #else
- typedef ProcPtr QueueUSBReadUPP;
- typedef ProcPtr QueueUSBWriteUPP;
- typedef ProcPtr IODoneUPP;
- typedef ProcPtr AbortUPP;
- typedef ProcPtr ControlStatusUPP;
- #endif
-
- typedef struct {
- OSErr err;
- IOParamPtr pb;
- DCtlPtr ctl;
- } DrvrParams;
-
- typedef union {
- char b;
- struct {
- unsigned reserved0:2;
- unsigned paperError:1;
- unsigned select:1;
- unsigned notError:1;
- unsigned reserved1:3;
- } status;
- } CentronicsStatusByte;
-
- typedef struct usbPrinterPBStruct
- {
- //
- // note: first element must be USBPB pb
- // since we often cast it to usbPrinterPBStruct
- //
- USBPB pb, // configuration block
- out, // map client write
- in; // map client read
- //
- // optional bulk in pipe
- //
- USBEndPointDescriptorPtr readDescriptor; // configuration/interface info
- USBPipeRef readPipeRef; // USB pipe reference
- QueueUSBReadUPP qread, // queue USB read from 68K
- r;
- RoutineDescriptor qreadRD; // static descriptor
- DrvrParams readDrvr; // currently active read
- int readRetryCount; // retry transactions
- //
- // mandatory bulk out pipe
- //
- USBEndPointDescriptorPtr writeDescriptor; // configuration/interface info
- USBPipeRef writePipeRef; // USB pipe reference
- QueueUSBWriteUPP qwrite, // queue USB write from 68K
- w;
- RoutineDescriptor qwriteRD; // static descriptor
- DrvrParams writeDrvr; // currently active read
- int writeRetryCount; // retry transactions
- //
- // abort/cancel transactions
- //
- AbortUPP qabort, // cancel from 68K DRVR
- a;
- RoutineDescriptor qabortRD; // static descriptor
- //
- // status transactions
- //
- ControlStatusUPP qstatus, // simple status from 68K DRVR
- s;
- RoutineDescriptor qstatusRD; // static descriptor
- DrvrParams statusDrvr; // currently active status request
- //
- // unit table driver names and refNums
- //
- DRVRHeaderHandle hDrvr; // detached from class driver resource file
- DriverRefNum outRefNum; // write unit table ref
- DriverRefNum inRefNum; // read unit table ref
- Str255 driverOutName; // write driver name in unit table
- Str255 driverInName; // read driver name in unit table
- //
- // device: configuration and interface details
- //
- UInt8 terminating; // offline USS-720 device
- USBDeviceRef deviceRef; // USB device reference
-
- USBDeviceDescriptor deviceDescriptor;
- USBInterfaceDescriptorPtr pInterfaceDescriptor;
- UInt32 interfaceOffset; // result/param for USB calls
- UInt8 whichAltInterface;
-
- Str255 devclass; // printer class in name registry
- Str255 model; // printer model in name registry
- Str255 name; // printer name in name registry
-
- unsigned char *pCapabilityString; // 1284 capability string
- USBConfigurationDescriptorPtr config; // USB configuration string
-
- unsigned char capability[256]; // capability: try not to fragment storage
- unsigned char configuration[256]; // configuration: try not to fragment storage
-
- CentronicsStatusByte centronics;
- //
- // we double-buffer i/o requests into our heap, using page aligned blocks
- //
- UInt32 pageWriteAlignedBufferSize,
- pageReadAlignedBufferSize;
- UInt8 *pageWriteAlignedBuffer,
- *pageReadAlignedBuffer,
- malignedBuffer[ 3*TRANSFER_SIZE ]; //PrintDriverEntry assumes 3*TRANSFER_SIZE
-
- //
- // class driver async transactions
- //
- SInt32 transDepth; // don't nest transactions
- SInt32 retryCount; // automatically retry transactions
-
- USBReference interfaceRef;
-
-
- UInt32 configurationNumber;
- UInt32 interfaceNumber;
- UInt32 printerProtocol;
- UInt32 alternateSetting;
- UInt32 pipeCount;
-
- Boolean delayInProgress;
- Boolean printerConfigured;
- Boolean printerRegistered;
-
- };
-
-
- OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct *pPrinterPB, UInt32 refCon);
- OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
- void ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
- void QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
- void QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
-
- void PrintDriverEntry(USBDeviceRef deviceRef, USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface, UInt32 interfaceNumber);
-
- OSStatus PrinterRemovalNotification( void );
-
- void hexstr( int count, char *p, char *q );
-
-
-
- #endif //__PRINTERCLASSDRIVERH__